package fr.pud.server;

import java.io.File;
import java.io.IOException;

import fr.pud.utils.Tools4Files;

public class CalculationThread extends Thread {
    public static final String mapFile = "";
    private int                nodesNumber;
    private long[]             inputData;
    private String             inputName;
    private String             outputName;

    public CalculationThread() {
        super();
    }

    public CalculationThread(int nodesNumber, long[] inputData,
            String iNetAddress) {
        this.nodesNumber = nodesNumber;
        this.inputData = inputData;
        this.inputName = iNetAddress + "_input";
        this.outputName = iNetAddress + "_output";
    }

    @Override
    public void run() {
        super.run();
        try {
            Tools4Files.writeNodes(this.inputName, this.inputData);
            Runtime.getRuntime().exec(
                    "DistanceMatrix -nodesnb=" + this.nodesNumber
                            + " -inputfile=" + this.inputName + " -outputfile="
                            + this.outputName + " -mapfile=" + mapFile);
            File f = new File(this.outputName);
            while (!f.exists()) {
                this.wait();
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
